﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pos.excption;
using System.Collections;
using Spring.Data.NHibernate.Support;
using Spring.Data.NHibernate;
using NHibernate;
using NHibernate.Criterion;

namespace pos.entity
{
    class ReturnedSettle: IHibernateCallback
    {
      
         public object DoInHibernate(ISession session)
        {



                t_returned returned = new t_returned();
          

                SettleTool tool = new SettleTool();

                //DataSet set = returned.query("", "order by seqID");
                //DataTable t = set.Tables[0];

                IList list = returned.List(returned.DC.AddOrder(Order.Asc("seqID")));
                long i = 0;

                foreach (Returned r in list)
                {
                    returned.Init(r);

                    tool.Setttle(returned);
                 //   setSettleMsg(i.ToString());

                    i++;

                 //   setSettleMsg(i.ToString());
                }
                tool.saveall();
                session.Flush();
                
             //   setSettleMsg("正在转移数据.....");
                //db.ExeSql("insert into t_hreturned (select * from t_returned where settleState=1 )");

//                db.ExeSql("delete from t_returned where settleState=1 ");
                ISQLQuery qr = session.CreateSQLQuery("insert into t_hreturned (select * from t_returned where settleState=1 )");
                qr.ExecuteUpdate();
                qr = session.CreateSQLQuery("delete from t_returned where settleState=1 ");
                qr.ExecuteUpdate();
              


             //   setSettleMsg("结算成功！");
              

          
        

            return true;
        }


    }
}
